package com.collabscm.pf.crypt;

/**
 * 安全加密器
 * @author Zeng Raoxing
 */
public class Cryptography {
	/**
	 * HASH加密算法
	 */
	private static HashEncryption hashEncryption;
	/**
	 * 对称加密算法
	 */
	private static SymmetricEncryption symmetricEncryption;
	
	/**
	 * 加密器配置类
	 * @author Zeng Raoxing
	 */
	public static class Configuration {
		
		protected void setHashEncryption(HashEncryption hashEncryption) {
			Cryptography.hashEncryption = hashEncryption;
		}
		
		protected void setSymmetricEncryption(SymmetricEncryption symmetricEncryption) {
			Cryptography.symmetricEncryption = symmetricEncryption;
		}
	}
	
	/**
	 * 将明文加密为密文
	 * @param plainText 明文
	 * @return 密文
	 */
	public static String encrypt(String plainText) {
		return symmetricEncryption.encrypt(plainText);
	}
	
	/**
	 * 解密密文
	 * @param ciphertext 密文
	 * @return 明文
	 */
	public static String decrypt(String ciphertext) {
		return symmetricEncryption.decrypt(ciphertext);
	}
	
	/**
	 * 明文生成密文
	 * @param plainText
	 */
	public static String createCiphertext(String plainText){
		return hashEncryption.createCiphertext(plainText);
	}
	
	/**
	 * 明文加密后的密文是否与传入的密文匹配？
	 * @param plainText  明文
	 * @param ciphertext 待比较的密文
	 */
	public static boolean martchCiphertext(String plainText, String ciphertext) {
		return hashEncryption.martchCiphertext(plainText, ciphertext);
	}

}
